<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<title>mywork</title>
		 <link href="../assets/css/bootstrap.css" rel="stylesheet" />
		 <link href="../assets/css/select2.min.css" rel="stylesheet" >
	     <!-- FontAwesome Styles-->
	    <link href="../assets/css/font-awesome.css" rel="stylesheet" />
	    <link href="../css/pulic.css" rel="stylesheet"/>
	     <!-- Google Fonts-->
	   <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
	     <!-- TABLE STYLES-->
	    <link href="../assets/js/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
	    <script src="../js/layui/layui.js"></script>  
		 <style media="screen">
        	.ECalendar{width:120px;height:30px;}
    	</style>
	</head>
	<body>
		<!--<div class="panel panel-default">-->
                   <div class="row" style="margin-left: 23%;margin-top:2%">
						<form class="form-inline" id="quertUserInfo" >
							<div class="form-group">                      
                                <input type="text" class="form-control" name="userId" placeholder="请输入员工编号">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="userName" placeholder="请输入员工姓名">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="departmentName" placeholder="请输入所属部门">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="userTypeName" placeholder="请输入职级">
                            </div>
							<div class="form-group">                      
                                <input type="text" class="form-control" name="companyName" placeholder="请输入所属公司">
                            </div>
                        </form>
                        <button class="btn btn-info" onclick="quertUserInfo()">搜索</button>
					</div>
					 
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>员工编号</th>
                                            <th>员工姓名</th>
                                            <th>所属部门</th>
                                            <th>职级</th>
                                            <th>所属公司</th>
                                            <th>联系方式</th>
											<th>银行帐号</th>
                                            <th>修改密码</th>
                                            <th>再次输入密码</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="tbd">
                                    	<!--以下需要重复使用的部分-->
                                    	<c:forEach items="${userMsglist}" var="msglist">
		                                    <tr id="${msglist.userId }">
		                                        <td class="tet" name="userId" >${msglist.userId }</td>
		                                        <td class="tet" name="userName" >${msglist.userName }</td>
		                                        <td><input type="text" class="form-control" name="departmentName" placeholder="请输入所属部门" value="${msglist.departmentName }"></td>
		                                        <td><input type="text" class="form-control" name="userTypeName" placeholder="请输入职级" value="${msglist.userTypeName }"></td>
		                                        <td><input type="text" class="form-control" name="companyName" placeholder="请输入所属公司" value="${msglist.companyName }"></td>
		                                        <td><input type="text" class="form-control input-text size-S inputCard" id="phoneNum" onblur="checkPhone()" name="phone" placeholder="请输入联系方式" value="${msglist.phone }"></td>
												<td><input type="text" class="form-control input-text size-S inputCard" id="bankCardNumber"  name="bankNumber" onblur="getNum()" placeholder="请输入银行卡号" value="${msglist.bankNumber }"></td>
		                                        <td><input type="password" class="form-control" name="password" placeholder="请输入新密码"></td>
		                                        <td><input type="password" class="form-control" name="repassword" placeholder="请再次输入密码"></td>
		                                        <td>
			                                        <button class="btn btn-danger" name="${msglist.userId }" onclick="delUserMsg(this)">删除</button>
			                                        <button class="btn btn-warning" name="${msglist.userId }" onclick="updateUserMsg(this)">修改</button>
			                                        <button class="btn btn-info">取消</button>
		                                        </td>
		                                      </tr>
                                        </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!--分页功能-->
                         <div class="row" style="margin-left: 25%;margin-bottom:1%">
                   	<div class="col-sm-6">
                   		<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                   			<ul class="pagination">
                   				<li class="paginate_button previous" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
                   					<a href="getUserMsg.do?pageNow=1">首页</a>
                   				</li>
								<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
								  <c:choose> 
								   <c:when test="${page.pageNow - 1 > 0}"> 
								    <a href="getUserMsg.do?pageNow=${page.pageNow - 1}" rel="external nofollow" >上一页</a> 
								   </c:when> 
								   <c:when test="${page.pageNow - 1 <= 0}"> 
								    <a href="getUserMsg.do?pageNow=1" rel="external nofollow" rel="external nofollow" >上一页</a> 
								   </c:when> 
								  </c:choose> 
								</li>
								<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
									<a>第 ${page.pageNow} 页</a>
								</li>
								<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
									<c:choose> 
									<c:when test="${page.totalPageCount==0}"> 
										<a href="getUserMsg.do?pageNow=${page.pageNow}" rel="external nofollow" rel="external nofollow" >下一页</a> 
									</c:when> 
									<c:when test="${page.pageNow + 1 < page.totalPageCount}"> 
									    <a href="getUserMsg.do?pageNow=${page.pageNow + 1}" rel="external nofollow" >下一页</a> 
									</c:when> 
									<c:when test="${page.pageNow + 1 >= page.totalPageCount}"> 
									    <a href="getUserMsg.do?pageNow=${page.totalPageCount}" rel="external nofollow" rel="external nofollow" >下一页</a> 
									</c:when> 
									</c:choose> 
								</li>
								<li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">
								  <c:choose> 
								   <c:when test="${page.totalPageCount==0}"> 
								    <a href="getUserMsg.do?pageNow=${page.pageNow}" rel="external nofollow" rel="external nofollow" >尾页</a> 
								   </c:when> 
								   <c:otherwise> 
								    <a href="getUserMsg.do?pageNow=${page.totalPageCount}" rel="external nofollow" rel="external nofollow" >尾页</a> 
								   </c:otherwise> 
								  </c:choose> 
								</li>
                   			</ul>
                   		</div>
                   	</div>
                   </div>
                    <!--新增功能-->
                   <div class="row" style="margin-left: 4%;">
						<form class="form-inline" id="insertUserInfo" >
                            <div class="form-group">                      
                                <input type="text" class="form-control" name=userName placeholder="请输入员工姓名">
                            </div>
                            <div class="form-group"> 
                            	<input type="text" class="form-control" name="departmentName" placeholder="输入所属部门">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="userTypeName" placeholder="请输入职称">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="companyName" placeholder="请输入所属公司">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="phone" onblur="checkPhone()" placeholder="请输入联系方式">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="bankNumber"  name="bankCardNumber" onblur="getNum()" placeholder="请输入银行卡号">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="password" placeholder="请设置密码">
                            </div>
                            <div class="form-group">                      
                                <input type="text" class="form-control" name="repassword" placeholder="请再次输入密码">
                            </div>
                        </form>
                        <button class="btn btn-primary" onclick="insertUserMsg()">新增</button>
					</div>
				<script type="text/javascript">
					//idName为标签ID
					function getKeyAndValue(idName){
						var str = "{";
						console.log(idName);
						console.log("#"+idName+" td .form-control");
						var sss = $("#"+idName+" td .form-control");
						var ss = $("#"+idName+" .tet");
						$.each(ss, function(){ 
							str += '"'+$(this).attr('name')+'":"'+$(this).text()+'",';
						});
						$.each(sss, function(){ 
							str += '"'+$(this).attr('name')+'":"'+$(this).val()+'",'; 
						});
						str = str.substr(0, str.length - 1); 
						str += "}";
						console.log(str);
						console.log(typeof str);
						return str;
					}
			    	//ajax请求，删除用户
			    	function delUserMsg(obj){
			    		var userId = obj.getAttribute("name");
			    		$.ajax({
			    			url:"${pageContext.request.contextPath}/user/deleteEmployeeInformation.do",
			    			type:"post",
			    			dataType:"json",
			    			data:{"userId":userId,"pageNow":1},
			    			success:function(data){
			    				console.log("请求成功");
			    				if(data == null || data == ""){
			    					console.log("没数据");
			    				}else{
			    					var str = "";
			    					$("#tbd").children().remove();
			    					if(data.num == 0 ){ 
			    				        layer.msg("删除失败！");
			    					}else {
			    						layer.msg("删除成功！");
			    					}
									$.each(data.userMsglist,function(key,val){
										str += '<tr><td name="userId" class="tet">'+val.userId+'</td><td name="userName" class="tet">'+val.userName 
										+'</td><td><input type="text" name="departmentName" class="form-control"placeholder="请输入所属部门" value="'+val.departmentName
										+'"></td><td><input type="text" name="userTypeName" class="form-control"placeholder="请输入职级" value="'+val.userTypeName
										+'"></td><td><input type="text" name="companyName" class="form-control"placeholder="请输入所属公司" value="'+val.companyName
										+'"></td><td><input type="text" name="phone" class="form-control input-text size-S inputCard" id="phoneNum" onblur="checkPhone()" placeholder="请输入联系方式" value="'+val.phone
										+'"></td><td><input type="text" name="bankNumber" class="form-control input-text size-S inputCard" id="bankCardNumber" onblur="getNum()" placeholder="请输入银行卡号" value="'+val.bankNumber
										+'"></td><td><input type="password" name="password" class="form-control"placeholder="请输入新密码"></td>'
			                            +'<td><input type="password" name="repassword" class="form-control"placeholder="请再次输入密码"></td>'
			                            +'<td><a href="#" class="btn btn-danger" name="'+val.userId+
			                            '" onclick="delUserMsg(this)">删除</a>'
			                            +'<a href="#" class="btn btn-warning" name="'+val.userId
			                            +'" onclick="updateUserMsg(this)">修改</a>'
			                            +'<a href="#" class="btn btn-info">取消</a>'
			                            +'</td></tr>';
									});
									$("#tbd").append(str);
									str = "";
									str = '<ul class="pagination">'
		                   				+'<li class="paginate_button previous" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">'
		                   				+'<a href="getUserMsg.do?pageNow=1">首页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow-1+'" rel="external nofollow">上一页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a>第'+ data.page.pageNow +'页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow+1+'" rel="external nofollow">下一页</a></li>'
										+'<li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">'
										+'<a href="getUserMsg.do?'+data.page.totalPageCount+'" rel="external nofollow">尾页</a>'
										+'</li></ul>';
									console.log(str);
									$("#dataTables-example_paginate").append(str);
			    				}
			    			},
			    			error:function(data){
			    				console.log(data);
			    			}
			    		});
			    	}
			    	//ajax请求，修改用户
			    	function updateUserMsg(obj){
			    		var userId = obj.getAttribute("name");
			    		var str = getKeyAndValue(userId);
			    		console.log(str);
			    		str = str.replace('"{','{');
			    		console.log(typeof str);
			    		$.ajax({
			    			url:"${pageContext.request.contextPath}/user/updateEmployeeInformation.do",
			    			type:"post",
			    			data: {"params":str},
			    			dataType:"json",
			    			success:function(data){
			    				console.log("请求成功");
			    				if(data.num == null || data.num == ""){
			    					layer.msg(data.msg);
			    				}else{
			    					var str = "";
			    					$("#tbd").children().remove();
			    				    layer.msg(data.msg);
									$.each(data.userMsglist,function(key,val){
										str += '<tr><td name="userId">'+val.userId+'</td><td name="userName">'+val.userName 
										+'</td><td><input type="text" name="departmentName" class="form-control"placeholder="请输入所属部门" value="'+val.departmentName
										+'"></td><td><input type="text" name="userTypeName" class="form-control"placeholder="请输入职级" value="'+val.userTypeName
										+'"></td><td><input type="text" name="companyName" class="form-control"placeholder="请输入所属公司" value="'+val.companyName
										+'"></td><td><input type="text" name="phone" class="form-control input-text size-S inputCard" id="phoneNum" onblur="checkPhone()" placeholder="请输入联系方式" value="'+val.phone
										+'"></td><td><input type="text" name="bankNumber" class="form-control input-text size-S inputCard" id="bankCardNumber"  name="bankNumber" onblur="getNum()" placeholder="请输入银行卡号" value="'+val.bankNumber
										+'"></td><td><input type="password" name="password" class="form-control"placeholder="请输入新密码"></td>'
			                            +'<td><input type="password" name="repassword" class="form-control"placeholder="请再次输入密码"></td>'
			                            +'<td><a href="#" class="btn btn-danger" name="'+val.userId+
			                            '" onclick="delUserMsg(this)">删除</a>'
			                            +'<a href="#" class="btn btn-warning" name="'+val.userId
			                            +'" onclick="updateUserMsg(this)">修改</a>'
			                            +'<a href="#" class="btn btn-info">取消</a>'
			                            +'</td></tr>';
									});
									$("#tbd").append(str);
									str = "";
									str = '<ul class="pagination">'
		                   				+'<li class="paginate_button previous" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">'
		                   				+'<a href="getUserMsg.do?pageNow=1">首页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow-1+'" rel="external nofollow">上一页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a>第'+ data.page.pageNow +'页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow+1+'" rel="external nofollow">下一页</a></li>'
										+'<li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">'
										+'<a href="getUserMsg.do?'+data.page.totalPageCount+'" rel="external nofollow">尾页</a>'
										+'</li></ul>';
									console.log(str);
									$("#dataTables-example_paginate").append(str);
			    				}
			    			},
			    			error:function(data){
			    				console.log(data);
			    			}
			    		});
			    	}
			    	//ajax新增用户
			    	function insertUserMsg(){
				    	$.ajax({
				    		url:"${pageContext.request.contextPath}/user/insertEmployeeInformation.do",
				    		type:"post",
				    		data: $("#insertUserInfo").serialize(),
				    		dataType:"json",
				    		success:function(data){
				    			console.log("请求成功");
				    			if(data == null || data == ""){
				    				layer.msg("增加失败！");
				    			}else{
				    				var str = "";
				    				$("#tbd").children().remove();
				    				$("#dataTables-example_paginate").children().remove();
				    			    layer.msg(data.msg);
									$.each(data.userMsglist,function(key,val){
										str += '<tr><td name="userId">'+val.userId+'</td><td name="userName">'+val.userName 
										+'</td><td><input type="text" name="departmentName" class="form-control"placeholder="请输入所属部门" value="'+val.departmentName
										+'"></td><td><input type="text" name="userTypeName" class="form-control"placeholder="请输入职级" value="'+val.userTypeName
										+'"></td><td><input type="text" name="companyName" class="form-control"placeholder="请输入所属公司" value="'+val.companyName
										+'"></td><td><input type="text" name="phone" class="form-control input-text size-S inputCard" id="phoneNum" onblur="checkPhone()" placeholder="请输入联系方式" value="'+val.phone
										+'"></td><td><input type="text" name="bankNumber" class="form-control input-text size-S inputCard" id="bankCardNumber"  name="bankNumber" onblur="getNum()" placeholder="请输入银行卡号" value="'+val.bankNumber
										+'"></td><td><input type="password" name="password" class="form-control"placeholder="请输入新密码"></td>'
				                        +'<td><input type="password" name="repassword" class="form-control"placeholder="请再次输入密码"></td>'
				                        +'<td><a href="#" class="btn btn-danger" name="'+val.userId+
				                        '" onclick="delUserMsg(this)">删除</a>'
				                        +'<a href="#" class="btn btn-warning" name="'+val.userId
				                        +'" onclick="updateUserMsg(this)">修改</a>'
				                        +'<a href="#" class="btn btn-info">取消</a>'
				                        +'</td></tr>';
									});
									$("#tbd").append(str);
									/* var totalPageCount = data.page.totalPageCount;
									var pageNow = data.page.pageNow;
									if(data.page.pageNow - 1 <= 0){
										pageNow = 2;
									}
									console.log(data.page.totalPageCount);
									console.log(data.page.pageNow);
									if(data.page.pageNow + 1 > totalPageCount){
										data.page.pageNow = totalPageCount-1;
									}
									console.log("-----!-----");
									console.log(data.page.totalPageCount);
									console.log(data.page.pageNow); */
									str = "";
									str = '<ul class="pagination">'
		                   				+'<li class="paginate_button previous" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">'
		                   				+'<a href="getUserMsg.do?pageNow=1">首页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow-1+'" rel="external nofollow">上一页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a>第'+ data.page.pageNow +'页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow+1+'" rel="external nofollow">下一页</a></li>'
										+'<li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">'
										+'<a href="getUserMsg.do?'+data.page.totalPageCount+'" rel="external nofollow">尾页</a>'
										+'</li></ul>';
									console.log(str);
									$("#dataTables-example_paginate").append(str);
				    			}
				    		},
				    		error:function(data){
				    			console.log(data);
				    		}
				    	});
			    	}
			    	//多条件查询
			    	function quertUserInfo(){
				    	$.ajax({
				    		url:"${pageContext.request.contextPath}/user/getEmployeeInformation.do",
				    		type:"post",
				    		data: $("#quertUserInfo").serialize(),
				    		dataType:"json",
				    		success:function(data){
				    			console.log("请求成功");
				    			if(data == null || data == ""){
				    				console.log("没数据");
				    				$("#tbd").children().remove();
				    			}else{
				    				var str = "";
				    				$("#tbd").children().remove();
				    			    layer.msg(data.msg);
									$.each(data.userMsglist,function(key,val){
										str += '<tr><td name="userId">'+val.userId+'</td><td name="userName">'+val.userName 
										+'</td><td><input type="text" name="departmentName" class="form-control"placeholder="请输入所属部门" value="'+val.departmentName
										+'"></td><td><input type="text" name="userTypeName" class="form-control"placeholder="请输入职级" value="'+val.userTypeName
										+'"></td><td><input type="text" name="companyName" class="form-control"placeholder="请输入所属公司" value="'+val.companyName
										+'"></td><td><input type="text" name="phone" class="form-control input-text size-S inputCard" id="phoneNum" onblur="checkPhone()" placeholder="请输入联系方式" value="'+val.phone
										+'"></td><td><input type="text" name="bankNumber" class="form-control input-text size-S inputCard" id="bankCardNumber"  name="bankNumber" onblur="getNum()" placeholder="请输入银行卡号" value="'+val.bankNumber
										+'"></td><td><input type="password" name="password" class="form-control"placeholder="请输入新密码"></td>'
				                        +'<td><input type="password" name="repassword" class="form-control"placeholder="请再次输入密码"></td>'
				                        +'<td><a href="#" class="btn btn-danger" name="'+val.userId+
				                        '" onclick="delUserMsg(this)">删除</a>'
				                        +'<a href="#" class="btn btn-warning" name="'+val.userId
				                        +'" onclick="updateUserMsg(this)">修改</a>'
				                        +'<a href="#" class="btn btn-info">取消</a>'
				                        +'</td></tr>';
									});
									$("#tbd").append(str);
									str = "";
									str = '<ul class="pagination">'
		                   				+'<li class="paginate_button previous" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">'
		                   				+'<a href="getUserMsg.do?pageNow=1">首页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow-1+'" rel="external nofollow">上一页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a>第'+ data.page.pageNow +'页</a></li>'
										+'<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">'
										+'<a href="getUserMsg.do?'+data.page.pageNow+1+'" rel="external nofollow">下一页</a></li>'
										+'<li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">'
										+'<a href="getUserMsg.do?'+data.page.totalPageCount+'" rel="external nofollow">尾页</a>'
										+'</li></ul>';
									console.log(str);
									$("#dataTables-example_paginate").append(str);
				    			}
				    		},
				    		error:function(data){
				    			console.log(data);
				    		}
				    	});
			    	}
			    </script>
	</body>
	<script src="../assets/js/jquery-1.10.2.js"></script>
	
      	
      <!-- Bootstrap Js -->
    <script src="../assets/js/bootstrap.min.js"></script>
    <script src="../assets/js/select2.full.min.js"></script>
    <!-- Metis Menu Js -->
    <script src="../assets/js/jquery.metisMenu.js"></script>
     <!-- DATA TABLE SCRIPTS -->
    <script src="../assets/js/dataTables/jquery.dataTables.js"></script>
    <script src="../assets/js/dataTables/dataTables.bootstrap.js"></script>
         <!-- Custom Js -->
    <script src="../assets/js/custom-scripts.js"></script>
    <script src="../js/Ecalendar.jquery.min.js"></script>
    <script src="../assets/js/select2.full.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
		  $(".selectbox").select2();
		});
	</script>
      <!-- Custom Js -->
    <script src="../assets/js/custom-scripts.js"></script>
    <script>
    	//得到输入的银行卡号
    	function getNum(){
    	 var bankCardNumber = $("#bankCardNumber").val();//银行卡的id应该是动态id
    	 CheckBankNo(bankCardNumber);
    	}
    	
    	
    	
    	
//银行卡号Luhn校验算法
//luhn校验规则：16位银行卡号（19位通用）: 
//1.将未带校验位的 15（或18）位卡号从右依次编号 1 到 15（18），位于奇数位号上的数字乘以 2。
//2.将奇位乘积的个十位全部相加，再加上所有偶数位上的数字。
//3.将加法和加上校验位能被 10 整除。

//bankno为银行卡号
 function luhnCheck(bankno){
     var lastNum=bankno.substr(bankno.length-1,1);//取出最后一位（与luhn进行比较）
 
     var first15Num=bankno.substr(0,bankno.length-1);//前15或18位
     var newArr=new Array();
     for(var i=first15Num.length-1;i>-1;i--){    //前15或18位倒序存进数组
         newArr.push(first15Num.substr(i,1));
     }
     var arrJiShu=new Array();  //奇数位*2的积 <9
     var arrJiShu2=new Array(); //奇数位*2的积 >9
     
     var arrOuShu=new Array();  //偶数位数组
     for(var j=0;j<newArr.length;j++){
         if((j+1)%2==1){//奇数位
             if(parseInt(newArr[j])*2<9)
             arrJiShu.push(parseInt(newArr[j])*2);
             else
             arrJiShu2.push(parseInt(newArr[j])*2);
         }
         else //偶数位
         arrOuShu.push(newArr[j]);
     }
     
     var jishu_child1=new Array();//奇数位*2 >9 的分割之后的数组个位数
     var jishu_child2=new Array();//奇数位*2 >9 的分割之后的数组十位数
     for(var h=0;h<arrJiShu2.length;h++){
         jishu_child1.push(parseInt(arrJiShu2[h])%10);
         jishu_child2.push(parseInt(arrJiShu2[h])/10);
     }        
     
     var sumJiShu=0; //奇数位*2 < 9 的数组之和
     var sumOuShu=0; //偶数位数组之和
     var sumJiShuChild1=0; //奇数位*2 >9 的分割之后的数组个位数之和
     var sumJiShuChild2=0; //奇数位*2 >9 的分割之后的数组十位数之和
     var sumTotal=0;
     for(var m=0;m<arrJiShu.length;m++){
         sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
     }
     
     for(var n=0;n<arrOuShu.length;n++){
         sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
     }
     
     for(var p=0;p<jishu_child1.length;p++){
         sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
         sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
     }      
     //计算总和
     sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
     
     //计算luhn值
     var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;        
     var luhn= 10-k;
     
     if(lastNum==luhn){
        console.log("验证通过");
         return true;
     }else{
        layer.msg("银行卡号必须符合luhn校验");
         return false;
     }        
 }
 //使用layui声明
 layui.use('layer', function(){
  			var layer = layui.layer;
  		});  

 //检查银行卡号
 function CheckBankNo(bankno) {
     var bankno = bankno.replace(/\s/g,'');
     if(bankno == "") {
         layer.msg("请填写银行卡号");
         return false;
     }
     if(bankno.length < 16 || bankno.length > 19) {
         layer.msg("银行卡号长度必须在16到19之间");
         return false;
     }
     var num = /^\d*$/;//全数字
     if(!num.exec(bankno)) {
         layer.msg("银行卡号必须全为数字");
         return false;
     }
     //开头6位
     var strBin = "10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
     if(strBin.indexOf(bankno.substring(0, 2)) == -1) {
         layer.msg("银行卡号开头6位不符合规范");
         return false;
     }
     //Luhn校验
     if(!luhnCheck(bankno)){
         return false;
     }
     return true;
 }
 
 
 
 //验证电话号码
 function checkPhone(){
 	var phoneNum = $("#phoneNum").val();
 	if(phoneNum == "" ){ 
        layer.msg("手机号码为空，请填写!");
        return;
    }else if(!(/^1[34578]\d{9}$/.test(phoneNum))){ 
        layer.msg("手机号码有误，请重填!");  
      
    } 
 }
    </script>
</html>